package practice.doublets;

import java.util.HashMap;
import java.util.Map;
import java.util.PriorityQueue;
import java.util.Scanner;
import java.util.Stack;

public class Main {

	static char[] alphabet = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
	
	String[] strings;
	Map<String,Node> stringSet;
	String[][] neighbors;
	int[]numNeighbors;	
	
	public Main() {
		Scanner s = new Scanner(System.in);
		
		strings = new String[25143];
		
		stringSet = new HashMap<String,Node>();

		boolean dic=true;
		boolean first=true;
		int diclength=0;
		while (s.hasNext()){
			String line = s.nextLine();
			if (line.equals("")){
				dic = false;
				neighbors = new String[diclength][16*25];
				numNeighbors = new int[diclength];
				findNeighbors(diclength);
			}
			else if (dic){
				if (!stringSet.keySet().contains(line)){
					strings[diclength]=line;
					stringSet.put(line,new Node(diclength));
					diclength++;
				}
			}
			else{
				if (!first)
					System.out.println("");
				first =false;
				
				Scanner ss = new Scanner(line);
				String start=ss.next(), end=ss.next();
				int pathLength = dijkstra(stringSet.get(start),stringSet.get(end));
				
				if (pathLength==Integer.MAX_VALUE)
					System.out.println("No solution.");
				else
					printTrail(stringSet.get(start),stringSet.get(end));
			}
		}
	}
	public void findNeighbors(int diclength){
		for (int i=0; i < diclength; i++){
			int length=strings[i].length();
			int numseen=0;
			for (int j=0; j<length;j++){
				for (int k=0; k < 26;k++){
					if (alphabet[k]!=strings[i].charAt(j)){
						String newString = strings[i].substring(0,j)+alphabet[k]+strings[i].substring(j+1,length);
						if (stringSet.keySet().contains(newString)){
							neighbors[i][numseen]=newString;
							numseen++;
						}
					}
				}
			}
			numNeighbors[i]=numseen;
		}
	}
	public void printTrail(Node start,Node end){
		Stack<String> s = new Stack<String>();
		Node cur=end;
		while (cur!=start){
			s.add(strings[cur.id]);
			for (int i =0; i < numNeighbors[cur.id]; i++){
				Node n = stringSet.get(neighbors[cur.id][i]);
				if (n.distance< cur.distance){
					cur=n;
					break;
				}
			}
		}
		s.add(strings[start.id]);
		while (!s.isEmpty()){
			System.out.println(s.pop());
		}
	}
	public int dijkstra(Node start, Node end){
		PriorityQueue<Node> pq = new PriorityQueue<Node>();
		
		start.distance=0;
		pq.add(start);
		
		for (String s : stringSet.keySet()){
			Node n = stringSet.get(s);
			if (n!=start){
				n.distance=Integer.MAX_VALUE;
				pq.add(n);
			}
		}
		
		while (!pq.isEmpty()){
			Node current = pq.poll();
			for (int i =0; i < numNeighbors[current.id]; i++){
				Node e = stringSet.get(neighbors[current.id][i]);
				if (current.distance+1<e.distance){
					e.distance=current.distance+1;
					pq.remove(e);
					pq.add(e);
				}
			}
		}
		return end.distance;
	}
	class Node implements Comparable<Node>{
		int distance;
		int id;
		
		public Node(int id){
			this.id=id;
			distance = Integer.MAX_VALUE;
		}
		@Override
		public int compareTo(Node o) {
			if (distance < o.distance)
				return -1;
			else if (distance == o.distance)
				return 0;
			else
				return 1;
		}
	}
	
	
	public static void main(String[] args) {
		new Main();
	}

}
